﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Electronic_work_order.Model;
using Electronic_work_order.Interfacess.OA_Permission;
namespace Electronic_work_order.Controllers
{
 
    [ApiController]
    public class OA_PermissionController : ControllerBase
    {
        private readonly Interface_Permission _permission;

        public OA_PermissionController(Interface_Permission permission)
        {
            _permission = permission;
        }

        [HttpGet]
        [Route("[controller]/GetPermissions")]
        //查询权限+状态（链表）
        public IEnumerable<Permission> GetPermissions()
        {
           return _permission.GetPermissions();
        }

        [HttpGet]
        [Route("[controller]/GetRoles")]
        //查询角色表
        public IEnumerable<UserRole> GetRoles()
        {
            return _permission.GetRoles();
        }

        [HttpPut]
        [Route("[controller]/Update_QiYong_Sate")]
        //修改状态（启用）
        public int Update_QiYong_Sate(int PermissonID)
        {
            if (_permission.Update_QiYong_Sate(PermissonID)>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpPut]
        [Route("[controller]/Update_JinYong_Sate")]
        //修改状态（禁用）
        public int Update_JinYong_Sate(int PermissonID)
        {
            if (_permission.Update_JinYong_Sate(PermissonID) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
            [HttpPost]
        [Route("[controller]/AddUserRole")]
        //添加角色
        public int AddUserRole(UserRole role)
        {
            if (_permission.AddUserRole(role)>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        [Route("[controller]/GetRoles_MoHu")]
        //角色模糊查询
        public IEnumerable<UserRole> GetRoles_MoHu(string RoleName)
        {
           return _permission.GetRoles_MoHu(RoleName);
        }
        [HttpGet]
        [Route("[controller]/getState_Role_permissions")]
        //角色管理页面点击分配权限展示的数据
        public IEnumerable<object> getState_Role_permissions()
        {
            return _permission.getState_Role_permissions();
        }
        [HttpPost]
        [Route("[controller]/Add_Role_Permission")]
        //添加角色+权限表 Role_Permission
        public int Add_Role_Permission(Role_Permission permission)
        {
            return _permission.Add_Role_Permission(permission);
        }
        
        }
}
